package com.qianbao.dao.user;


import com.qianbao.domain.user.UserEntity;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Repository;

@Mapper
@Repository
public interface UserDao {


    /**
     * 保存用户、新增用户
     * @param entity
     * @return
     */
    @Insert("insert into sys_user(id,avatar,account,password,phone,createtime) values(#{customId},#{avatar},#{account},#{password},#{phone},#{createTime})")
    public int saveAccount(UserEntity entity);


    /**
     * 检查数据库中这个手机号是否存在
     * @param phone
     * @return
     */
    @Select("select * from sys_user where phone = #{phone}")
    @Results(id="userEntityId",value = {
            @Result(column = "id", property = "customId",jdbcType = JdbcType.VARCHAR, id = true),
            @Result(column = "createtime", property = "createTime", jdbcType = JdbcType.DATE)
    })
    public UserEntity findAccountByPhone(String phone);


    /**
     * 更新用户信息  暂时是更新用户密码
     * @param phone
     * @param password
     * @return
     */
    @Update("update sys_user set password = #{password} where phone = #{phone}")
    public int updateUserAccount(@Param("phone")String phone,
                                 @Param("password") String password);


    /**
     * 通过手机号查询出用户的密码---用户修改用户密码
     * @param phone
     * @return
     */
    @Select("select password from sys_user where phone = #{phone}")
    public String findUserPasswordByPhone(String phone);




}
